home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------
-
- Program name: Windows demo program.
-
- Author: Gareth Williams
-
- Description: demonstrates the windows module by displacing a window
- with the lamp structure.
-
- Modification history : (Version), (Date), (Name), (Description).
-
- 1.0, 1st September 1991, G. Williams, First Version.
-
- 2.0, June 1992, G. Williams, Converted to ISO PHIGS C.
-
- SunOS requirements: SunPHIGS 2.0, OpenWindows 3.0.
-
- ----------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <math.h>
- #include <phigs.h>
- #include "ptk.h"
-
- #define WS1 1
- #define DEVICE1 1
- #ifdef SUN
- #define DEVICE2 4
- #endif
- #ifndef SUN
- #define DEVICE2 2
- #endif
- #define PI 3.14159
-
- /* Operating system dependent code, UNIX/VMS pathnames */
- /* UNIX pathnames */
- #define SCRIPTNAME "../scripts/lamp.scr"
- #define OPENWSNAME "../scripts/openws.scr"
-
- /*
- #ifdef VMS
- #define SCRIPTNAME "[-.scripts]lamp.scr"
- #endif
- */
-
- static char *colwrd[] =
- {
- "BLACK", "WHITE", "GREEN",
- "BLUE", "CYAN", "GREY", "RED"
- };
-
- static Pfloat devx, devy, devz;
-
- /*--------------------------------------------------------------------------*/
-
- static void init_input(C(void))
- /* Initializes four valuators in sample mode, and a choice
- ** device in event mode.
- */
- {
- Pin_status initstatus = PIN_STATUS_OK;
- Pint initview, err;
- Ppoint initpos;
- Ploc_data locrec;
- Plimit echo;
-
- pset_loc_mode(WS1, DEVICE1, POP_REQ, PSWITCH_ECHO);
- pset_loc_mode(WS1, DEVICE2, POP_REQ, PSWITCH_ECHO);
- echo = ptk_limit(0.0, devx, 0.0, devy);
- initview = 0;
- initpos = ptk_point(0.5, 0.5);
- #ifdef HP
- locrec.pets.pet_r1.loc_colr_ind = 1;
- #endif
- pinit_loc(WS1, DEVICE1, initview, &initpos, 1, &echo, &locrec);
- pinit_loc(WS1, DEVICE2, initview, &initpos, 1, &echo, &locrec);
- pset_loc_mode(WS1, DEVICE1, POP_EVENT, PSWITCH_ECHO);
- pset_loc_mode(WS1, DEVICE2, POP_SAMPLE, PSWITCH_ECHO);
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void camerainterface(C(Pint) windid)
- PreANSI(Pint windid)
- {
- Pint wsid, devnum, viewindex, err;
- Pin_class class;
- Pin_status status;
- Ppoint oldpos, pos;
- Plimit3 lims;
- Ppoint3 defcampos, campos;
- Pfloat zorg;
-
- init_input(); /* Initialise input devices. */
- oldpos = ptk_point(0.5, 0.5);
- ptk_inqcameralimits(windid, &lims, &err);
- ptk_inqcameraposition(windid, &defcampos, &err);
- zorg = lims.z_min + ((lims.z_max - lims.z_min) / 2.0);
- while (1)
- {
- psample_loc(WS1, DEVICE2, &viewindex, &pos);
- campos = ptk_point3(lims.x_min + (lims.x_max - lims.x_min) * pos.x,
- lims.y_min + (lims.y_max - lims.y_min) * pos.y,
- zorg +
- (sin(PI * pos.x) * sin(PI * pos.y)) *
- (defcampos.z - zorg));
- ptk_setcameraposition(windid, &campos);
- pupd_ws(WS1, PFLAG_PERFORM);
- #ifdef SUN
- pawait_event(0.25, &wsid, &class, &devnum);
- #endif
- #ifdef HP
- pawait_event(0.0, &wsid, &class, &devnum);
- #endif
- #ifdef PEXSI
- pawait_event(0.5, &wsid, &class, &devnum);
- #endif
- /* See if left button pressed. */
- if (class == PIN_LOC)
- break;
- }
- pset_loc_mode(WS1, DEVICE1, POP_REQ, PSWITCH_ECHO);
- pset_loc_mode(WS1, DEVICE2, POP_REQ, PSWITCH_ECHO);
- } /* camerainterface */
-
- /*--------------------------------------------------------------------------*/
-
- static void options(C(void))
- {
- char commandstr[20], writestr[50];
- Pint lencom, lenstr, err, elem1, elem2, lampid, currentwindow, red, green;
- ptkboolean quit;
- Ppoint pos, size;
- Plimit echoarea;
- Pint lampiconstid;
-
- quit = FALSE;
- currentwindow = 1;
- do
- {
- echoarea = ptk_limit(0.0, devx, 0.0, devy * 0.1);
- ptk_readstring(WS1, "camera", "Input command (default = camera)>",
- &echoarea, 20, commandstr, &lencom);
- if (strncmp(commandstr, "camera", lencom) == 0)
- {
- camerainterface(currentwindow);
- }
- else
- if (strncmp(commandstr, "position", lencom) == 0)
- {
- pos.x = ptk_readfloat(WS1, 0.5, "Input position, x (0.5) >", &echoarea);
- pos.y = ptk_readfloat(WS1, 0.5, "Input position, y (0.5) >", &echoarea);
- ptk_setwindowposition(currentwindow, &pos);
- }
- else
- if (strncmp(commandstr, "size", lencom) == 0)
- {
- Ppoint userpos, usersize;
-
- size.x = ptk_readfloat(WS1, 0.5, "Input size, x (0.5) >", &echoarea);
- size.y = ptk_readfloat(WS1, 0.5, "Input size, y (0.5) >", &echoarea);
- ptk_setwindowsize(currentwindow, &size);
- }
- else
- if (strncmp(commandstr, "iconposition", lencom) == 0)
- {
- pos.x = ptk_readfloat(WS1, 0.5, "Input icon position, x (0.5) >",
- &echoarea);
- pos.y = ptk_readfloat(WS1, 0.5, "Input icon position, y (0.5) >",
- &echoarea);
- ptk_seticonposition(currentwindow, &pos);
- }
- else
- if (strncmp(commandstr, "iconsize", lencom) == 0)
- {
- size.x = ptk_readfloat(WS1, 0.1, "Input icon size, x (0.1) >",
- &echoarea);
- size.y = ptk_readfloat(WS1, 0.1, "Input icon size, y (0.1) >",
- &echoarea);
- ptk_seticonsize(currentwindow, &size);
- }
- else
- if (strncmp(commandstr, "framesize", lencom) == 0)
- {
- size.x = ptk_readfloat(WS1, 0.01, "Input frame size, x (0.01) >",
- &echoarea);
- size.y = ptk_readfloat(WS1, 0.01, "Input frame size, y (0.01) >",
- &echoarea);
- ptk_setframesize(currentwindow, &size);
- }
- else
- if (strncmp(commandstr, "open", lencom) == 0)
- {
- ptk_openwindow(currentwindow);
- }
- else
- if (strncmp(commandstr, "close", lencom) == 0)
- {
- ptk_closewindow(currentwindow);
- }
- else
- if (strncmp(commandstr, "front", lencom) == 0)
- {
- ptk_frontwindow(currentwindow);
- }
- else
- if (strncmp(commandstr, "back", lencom) == 0)
- {
- ptk_backwindow(currentwindow);
- }
- else
- if (strncmp(commandstr, "bannerheight", lencom) == 0)
- {
- Pfloat height;
-
- height = ptk_readfloat(WS1, 0.01, "Input banner height >", &echoarea);
- ptk_setbannerheight(currentwindow, height);
- }
- else
- if (strncmp(commandstr, "bannercolours", lencom) == 0)
- {
- Pint bancol, titlecol;
-
- bancol = ptk_readint(WS1, 0, "Input banner colour index >",
- &echoarea);
- titlecol = ptk_readint(WS1, 1, "Input title string colour index >",
- &echoarea);
- ptk_setbannercolours(currentwindow, bancol, titlecol);
- }
- else
- if (strncmp(commandstr, "phinter", lencom) == 0)
- {
- ptk_callphinter();
- }
- else if (strncmp(commandstr, "hardcopy", lencom) == 0)
- {
- Pint stid, lenname;
- char filename[80];
-
- ptk_readstring(WS1, "window",
- "Input filename (default = window) >", &echoarea,
- 80, filename, &lenname);
-
- /* Implementation dependent code, open a hardcopy workstation */
- #ifdef SUN
- popen_ws(2, filename, phigs_ws_type_cgm_out);
- ptk_copyviewtable(1, 2);
- ptk_copypostedstruct(1, 2);
- pupd_ws(2, PFLAG_PERFORM);
- pclose_ws(2);
- #endif
- }
- else if (strncmp(commandstr, "help", lencom) == 0)
- {
- printf("windtest options\n");
- printf("----------------\n");
- printf("camera - start up camera interface\n");
- printf("position - set window position (centre)\n");
- printf("size - set window size\n");
- printf("iconposition - set icon position (centre)\n");
- printf("iconsize - set icon size\n");
- printf("framesize - set window frame thickness\n");
- printf("open - open window\n");
- printf("close - close window\n");
- printf("front - bring window/icon to front of display\n");
- printf("back - send window/icon to back of display\n");
- printf("bannerheight - set window banner height\n");
- printf("bannercolours - set window banner colours\n");
- printf("phinter - call phinterface\n");
- printf("hardcopy - post window to hardcopy workstation\n");
- printf("quit - exit windtest\n");
- }
- else
- if (strncmp(commandstr, "quit", lencom) == 0)
- {
- quit = TRUE;
- }
- else
- {
- printf("Command unknown\n");
- }
- pupd_ws(WS1, PFLAG_PERFORM);
- } while (quit == FALSE);
- }
-
- /*--------------------------------------------------------------------------*/
-
- main()
- {
- Pint wst, lampid, lampwindow;
- Pint_list lamplist;
- Ppoint pos, size;
- Pint white, black, green, grey, blue, textfont;
- ptkboolean docolour = FALSE;
-
- printf("Demonstrating the PHIGS windows module of the PHIGS Toolkit...\n");
-
- /* Implementation dependent code, open PHIGS and workstation */
- #if SUN
- printf("Opening SunPHIGS...\n");
- popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
-
- /* Open a workstation. */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
-
- /* popen_ws(WS1, (void *)NULL, wst);
- wst = phigs_ws_type_create( phigs_ws_type_x_tool,
- 0);
- */
- #endif
- #ifdef PEXSI
- printf("Opening PEX-SI PHIGS...\n");
- popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
- #endif
- #ifdef HP
- printf("Opening HP PHIGS...\n");
- popen_phigs(stderr, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
- #endif
- ptk_inqmaxdevicecoords(WS1, &devx, &devy);
- devz = 0.0;
-
- #ifdef SUN
- #ifndef SUNMONO
- docolour = TRUE;
- #endif
- #endif
- #ifdef HP
- #ifndef HPMONO
- docolour = TRUE;
- #endif
- #endif
- #ifdef PEXSI
- #ifndef PEXSIMONO
- docolour = TRUE;
- #endif
- #endif
-
- pset_disp_upd_st(WS1, PDEFER_WAIT, PMODE_NIVE);
-
- /* initialise hashtables */
-
- ptk_inithashtables();
- ptk_createhashtable("structureid", 1, 500);
- ptk_createhashtable("label", 1, 50);
- ptk_createhashtable("viewindex", 1, 50);
- ptk_createhashtable("colourindex", 1, 8);
- ptk_createhashtable("windowid", 1, 50);
- ptk_createhashtable("name", 1, 50);
-
- /* set colours */
- if (docolour)
- {
- ptk_setupcolourtable(WS1, 7, colwrd);
- green = ptk_stringtoint("colourindex", "green");
- grey = ptk_stringtoint("colourindex", "grey");
- white = ptk_stringtoint("colourindex", "white");
- black = ptk_stringtoint("colourindex", "black");
- blue = ptk_stringtoint("colourindex", "blue");
-
- /* Implementation dependent code, choose a nice font */
- #ifdef SUN
- textfont = PFONT_TRIPLEX;
- #endif
- #ifndef SUN
- textfont = 1;
- #endif
- ptk_setbackgroundcolourind(WS1, grey);
- }
-
- if (ptk_readphinterscript(SCRIPTNAME, NULL, NULL))
- {
- pos = ptk_point(0.5, 0.5);
- size = ptk_point(0.6, 0.6);
- lampwindow = ptk_stringtoint("windowid", "lampwindow");
- ptk_createwindow(WS1, lampwindow, &size, &pos, "lamp window");
- if (docolour)
- ptk_setwindowattrs(lampwindow, textfont, black,
- green, grey, green, white, black);
- ptk_posttowindow(ptk_stringtoint("windowid", "lampwindow"),
- ptk_stringtoint("structureid", "lamp"));
- lamplist.num_ints = 1;
- lamplist.ints = &lampid;
- lampid = ptk_stringtoint("structureid", "lamp");
- ptk_setcameraworld(ptk_stringtoint("windowid", "lampwindow"),
- &lamplist);
- ptk_postwindow(ptk_stringtoint("windowid", "lampwindow"));
- pupd_ws(WS1, PFLAG_PERFORM);
-
- pos = ptk_point(0.1, 0.9);
- ptk_seticonposition(ptk_stringtoint("windowid", "lampwindow"), &pos);
- options();
- ptk_unpostallfromwindow(ptk_stringtoint("windowid", "lampwindow"));
- }
-
- pclose_ws(WS1); /* Close workstation. */
- pclose_phigs(); /* Close PHIGS. */
- }
-
- /*--------------------------------------------------------------------------*/
-
- /* end of windtest.c */
-